﻿using System.Text.RegularExpressions;

namespace RuoVea.ExUtil.Validate
{
    /// <summary>
    /// 描 述：错误校验方法类
    /// </summary>
    public class Validate
    {
        /// <summary>
        /// 邮箱
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>布尔类型</returns>
        public static bool IsEmail(object value)
        {
            Regex r = new Regex(@"^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$");
            return r.IsMatch(value + "");
        }

        /// <summary>
        /// 身份证
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>布尔类型</returns>
        public static bool ICCare(object value)
        {
            Regex r = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
            return r.IsMatch(value + "");
        }
        /// <summary>
        /// 时间
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>布尔类型</returns>
        public static bool IsDate(object value)
        {
            Regex r = new Regex(@"^(((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d)$");
            return r.IsMatch(value + "");
        }

        /// <summary>
        /// 微信
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>布尔类型</returns>
        public static bool WeChart(object value)
        {
            Regex r = new Regex(@"^((((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})|([a-zA-Z]([-_a-zA-Z0-9]{5,19})+))$");
            return r.IsMatch(value + "");
        }

        /// <summary>
        /// 网址
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>布尔类型</returns>
        public static bool UURL(object value)
        {
            Regex r = new Regex(@"^((https?|ftp|news):\/\/)?([a-z]([a-z0-9\-]*[\.。])+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel)|(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&]*)?)?(#[a-z][a-z0-9_]*)?$");
            return r.IsMatch(value + "");
        }

        /// <summary>
        /// 手机
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>布尔类型</returns>
        public static bool IsPhone(object value)
        {
            Regex r = new Regex(@"^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$");
            return r.IsMatch(value + "");
        }

        /// <summary>
        /// 电话
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>布尔类型</returns>
        public static bool ForT(object value)
        {
            Regex r = new Regex(@"^$|(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$|^(13|15)\d{9}$");
            return r.IsMatch(value + "");
        }

        /// <summary>
        /// 数值 两位小数的数字
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>布尔类型</returns>
        public static bool Numbe2(object value)
        {
            Regex r = new Regex(@"^\d*(\.\d{1,2})?$");
            return r.IsMatch(value + "");
        }

        /// <summary>
        /// 数值 两位小数的数字
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="minLength"></param>
        /// <param name="maxLength"></param>
        /// <returns>布尔类型</returns>
        public static bool IsPassworld(object value, int minLength = 8, int maxLength = 32)
        {
            Regex r = new Regex(@"^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).{" + minLength + "," + maxLength + "}$");
            return r.IsMatch(value + "");
        }

        /// <summary>
        /// 数值 两位小数的数字
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="minLength"></param>
        /// <param name="maxLength"></param>
        /// <returns>布尔类型</returns>
        public static bool IsSuperPassworld(object value, int minLength = 8, int maxLength = 32)
        {
            Regex r = new Regex(@"^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=([\x21-\x7e]+)[^a-zA-Z0-9]).{" + minLength + "," + maxLength + "}$");
            return r.IsMatch(value + "");
        }
    }
}